<?php

namespace app\api\controller\supplier;

use app\admin\model\Mallsupplier;
use app\common\controller\Api;
use app\common\library\Ems;
use app\common\library\Sms;
use fast\Random;
use think\Config;
use think\Validate;

/**
 * 会员接口
 */
class User extends Api
{
    protected $noNeedLogin = ['login', 'resetpwd'];
    protected $noNeedRight = '*';

    public function _initialize()
    {
        parent::_initialize();


    }

    public function index()
    {

        $user = $this->auth->getUser();

    }


    public function login()
    {
        $account = $this->request->param('mobile');
        $password = $this->request->param('password');
        if (!$account || !$password) {
            $this->error(__('Invalid parameters'));
        }

        $mallSupplierModel = new Mallsupplier();
        $supplier = $mallSupplierModel->where('mobile',$account)->find();
        if(!$supplier) $this->error("您不是供应商身份");

        if($password != $supplier['password']){
            $this->error("密码错误");
        }

        $userModel = new \app\admin\model\User();
        $user =$userModel->where('mobile',$account)->find();
        $this->auth->direct($user['id']);
        $token = $this->auth->getToken();

        $ret = array();
        $ret['mobile'] = $account;
        $ret['token'] = $token;
        $ret['username'] = $supplier['name'];
        $this->success('',$ret);

    }




}
